home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / FontMancer / CDEF / Sources / cdef.c < prev   
C/C++ Source or Header  |  1996-06-21  |  2KB  |  96 lines

  1. //with Hints from ICONDef.c in MPW examples
  2.  
  3. #ifndef __CONTROLS__
  4. #include <Controls.h>
  5. #endif
  6.  
  7. #ifndef __FONTS__
  8. #include <Fonts.h>
  9. #endif
  10.  
  11. #ifndef __MEMORY__
  12. #include <Memory.h>
  13. #endif
  14.  
  15. #ifndef __TOOLUTILS__
  16. #include <ToolUtils.h>
  17. #endif
  18.  
  19. extern struct picStorage {
  20.     long        buttonHilite;
  21.     PicHandle    buttonNormal;
  22.     PicHandle    buttonPressed;
  23.     PicHandle    buttonInactUp;
  24.     PicHandle    buttonInactDown;
  25.     };
  26.  
  27. pascal long    main(short varCode, ControlHandle ctl, short msg, long parm);
  28.  
  29. pascal long    main(short varCode, ControlHandle ctl, short msg, long parm)
  30. {
  31.     struct picStorage        *buttonPic;
  32.     Point                    cursorLoc;
  33.     short                    cHilite,cValue;
  34.     
  35.     HLock((Handle) ctl);
  36.     buttonPic = (struct picStorage *) (**ctl).contrlRfCon;
  37.     cHilite = (**ctl).contrlHilite;
  38.     cValue = (**ctl).contrlValue;
  39.     if (StillDown() && (cHilite != 255)) buttonPic->buttonHilite = cHilite;
  40.     
  41.     switch (msg) {
  42.  
  43.         case drawCntl:
  44.             switch (varCode & (short)0xFFF7) {
  45.                 case 0:
  46.                 case 1:
  47.                 case 2:
  48.                     if (!buttonPic) {
  49.                         HUnlock((Handle) ctl);
  50.                         return(0);
  51.                         }
  52.                     if (cHilite == 255) {
  53.                         if (cValue)
  54.                             DrawPicture(buttonPic->buttonInactDown,&(**ctl).contrlRect);
  55.                         else
  56.                             DrawPicture(buttonPic->buttonInactUp,&(**ctl).contrlRect);
  57.                         break;
  58.                         }
  59.                     if (((buttonPic->buttonHilite) && cValue) || ((!buttonPic->buttonHilite) && !cValue))
  60.                         DrawPicture(buttonPic->buttonNormal,&(**ctl).contrlRect);
  61.                     else
  62.                         DrawPicture(buttonPic->buttonPressed,&(**ctl).contrlRect);
  63.                     break;
  64.                 case 3:
  65.                     EraseRect(&(**ctl).contrlRect);
  66.                     break;
  67.             }
  68.             break;
  69.  
  70.         case testCntl:
  71.             SetPt(&cursorLoc,LoWord(parm),HiWord(parm));
  72.             if (PtInRect(cursorLoc,&((**ctl).contrlRect))) return(1);
  73.                 else return(0);
  74.             break;
  75.         case calcCRgns:
  76.         case calcCntlRgn:
  77.             if (msg == calcCRgns)
  78.                 parm &= 0x00FFFFFF;
  79.             RectRgn((RgnHandle)parm, &(**ctl).contrlRect);
  80.             break;
  81.         case initCntl:
  82.         case dispCntl:
  83.         case posCntl:
  84.         case thumbCntl:
  85.         case dragCntl:
  86.         case autoTrack:
  87.             break;
  88.     }
  89.     if (!Button() && (cHilite !=255)) buttonPic->buttonHilite = cHilite;
  90.     HUnlock((Handle) ctl);
  91.     return(0);
  92. }
  93.  
  94.  
  95.  
  96.